package com.spzx.test1.t13;
/*
    并非全力
*/

import org.apache.commons.lang3.RandomUtils;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;

public class BreadRoom {



    BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(5);

    public void put(String bread) throws InterruptedException {
        System.out.println(Thread.currentThread().getName() + "向货架上放入一块面包" + bread);
        blockingQueue.put(bread);
        TimeUnit.SECONDS.sleep(RandomUtils.nextInt(1,2));
        System.out.println(blockingQueue);

    }

    public String get() throws InterruptedException {
        String take = blockingQueue.take();
        System.out.println(Thread.currentThread().getName() + "从货架上拿走一块面包" + take);

        TimeUnit.SECONDS.sleep(RandomUtils.nextInt(1,5));
        System.out.println(blockingQueue);
        return take;
    }


}
